package com.yc.shopping.ui;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;

import com.yc.shopping.util.ShoppingUtil;

import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class Dialog_memberPay extends Dialog {

	

	protected Object result;
	protected Shell shell;
	private Text text_total;
	private Text text_give;
	private Text text_ling;
	private Label label_3;
	private Text text_zk;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public Dialog_memberPay(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		shell.setSize(449, 350);
		shell.setText("支付");
		ShoppingUtil.centerWindows(shell);
		Label label = new Label(shell, SWT.NONE);
		label.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		label.setBounds(55, 33, 76, 33);
		label.setText("应收金额");
		
		Label label_1 = new Label(shell, SWT.NONE);
		label_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		label_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_1.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		label_1.setBounds(55, 97, 76, 33);
		label_1.setText("支付金额");
		
		Label label_2 = new Label(shell, SWT.NONE);
		label_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_2.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		label_2.setBounds(55, 199, 61, 25);
		label_2.setText("找零");
		
		text_total = new Text(shell, SWT.READ_ONLY);
		text_total.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		text_total.setBounds(176, 37, 167, 25);
		
		text_give = new Text(shell, SWT.BORDER);
		text_give.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		text_give.setBounds(176, 101, 167, 25);
		
		text_ling = new Text(shell, SWT.READ_ONLY);
		text_ling.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		text_ling.setBounds(176, 203, 167, 25);
		
		Button btn_end = new Button(shell, SWT.NONE);
		
		btn_end.setBounds(161, 263, 80, 27);
		btn_end.setText("完成");
		
		//设置应收金额
		
		text_total.setText(ShoppingUtil.totalPrice+"");
		
		label_3 = new Label(shell, SWT.NONE);
		label_3.setText("实收金额");
		label_3.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_3.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		label_3.setBounds(55, 153, 76, 25);
		
		text_zk = new Text(shell, SWT.READ_ONLY);
		text_zk.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 14, SWT.NORMAL));
		text_zk.setBounds(176, 155, 167, 23);
		float money =(float) Math.round((ShoppingUtil.totalPrice*0.95)*100)/100;
		text_zk.setText(money+"");
		text_give.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				//获取实收金额
				String give= text_give.getText().trim();
				text_ling.setText((Float.parseFloat(give)-money)+"");
			}
		});
		
		btn_end.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.dispose();
			}
		});
	}
}
